const RouterHook = require("../module/routerModule")
const {
    getReservationList,
    getReservationDetail,
    getReservationReservation
} = require("../service/reservation")
const router = RouterHook()
const dbUtil = require('../util/dbutil')
const {
    FieldUtils,
    AssertUtils
} = require("../util/utils")
/**
 * @swagger
 * /api/reservation/list:
 *    get:
 *      tags:
 *      - 维保预约接口
 *      summary: 预约历史
 *      produces:
 *      - application/json
 *      responses:
 *        200:
 *          description: 返回预约历史列表
 *          schema:
 *            type: object
 *            properties:
 *              id:
 *                type: number
 *              maintenance_type:
 *                type: string
 *                description: 维保类型
 *              city:
 *                type: string
 *                description: 城市
 *              service_station:
 *                type: string
 *                description: 维保服务站
 *              date:
 *                type: string
 *                description: 车辆id
 *              car_id:
 *                type: number
 *              name:
 *                type: string
 *                description: 联系人姓名
 *              tel:
 *                type: string
 *                description: 联系人电话
 * */

router.get('/list', async (ctx) => {
    let list = await getReservationList()
    ctx.result.success(list)
}).noAuth()

/**
 * @swagger
 * /api/reservation/detail:
 *    get:
 *      tags:
 *      - 维保预约接口
 *      summary: 预约详情
 *      produces:
 *      - application/json
 *      requestBody:
 *        required: true
 *        content:
 *          application/json:
 *            schema:
 *              type: object
 *              required:
 *                - id
 *      responses:
 *        200:
 *          description: 返回预约详情
 *          schema:
 *            type: object
 *            properties:
 *              id:
 *                type: string
 *              maintenance_type:
 *                type: string
 *              city:
 *                type: string
 *              service_station:
 *                type: string
 *              date:
 *                type: string
 *              car_id:
 *                type: number
 *              name:
 *                type: string
 *              tel:
 *                type: string
 *        500:
 *          description: id不能为空
 * */

router.get('/detail', async (ctx) => {
    const {
        id
    } = ctx.request.query
    AssertUtils.StringNotEmpty(id, "请输入id")
    let list = await getReservationDetail(id)
    ctx.result.success(list)
}).noAuth()

/**
 * @swagger
 * /api/reservation/reservation:
 *    get:
 *      tags:
 *      - 维保预约接口
 *      summary: 添加预约记录
 *      produces:
 *      - application/json
 *      parameters:
 *        - name: maintenance_type
 *          description: 维保类型
 *          required: true
 *          type: string
 *        - name: city
 *          description: 城市
 *          required: true
 *          type: string
 *        - name: service_station
 *          description: 维保服务站
 *          required: true
 *          type: string
 *        - name: date
 *          description: 预约日期
 *          required: true
 *          type: string
 *        - name: car_id
 *          description: 车辆id
 *          required: false
 *          type: string
 *        - name: name
 *          description: 联系人姓名
 *          required: true
 *          type: string
 *        - name: tel
 *          description: 联系人电话
 *          required: true
 *          type: string
 *      responses:
 *        200:
 *          description: 返回预约结果
 *        500:
 *          description: 不能为空
 * */

router.get('/reservation', async (ctx) => {
    const {
        maintenance_type,
        city,
        service_station,
        date,
        car_id,
        name,
        tel,
    } = ctx.request.query
    AssertUtils.StringNotEmpty(maintenance_type, "维保类型不能为空")
    AssertUtils.StringNotEmpty(city, "城市不能为空")
    AssertUtils.StringNotEmpty(service_station, "维保服务站不能为空")
    AssertUtils.StringNotEmpty(date, "预约日期不能为空")
    AssertUtils.StringNotEmpty(car_id, "车辆id不能为空")
    AssertUtils.StringNotEmpty(name, "联系人姓名不能为空")
    AssertUtils.StringNotEmpty(tel, "联系人电话不能为空")
    const list = await getReservationReservation({
        maintenance_type,
        city,
        service_station,
        date,
        car_id,
        name,
        tel,
    })
    ctx.result.success(list)
}).noAuth()

module.exports = router